package com.atom.process.cnmuseum.cj.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.impl.util.json.JSONArray;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.atom.common.entity.RunningTaskDO;
import com.atom.common.remote.user.UserUtil;
import com.atom.common.web.controller.AbstractMainController;
import com.atom.process.cnmuseum.cj.dao.task.CjGcxxTaskDao;
import com.atom.process.cnmuseum.cj.dao.task.CjTaskDao;
import com.atom.process.cnmuseum.cj.entity.task.CjGcxxTaskDO;
import com.atom.process.cnmuseum.cj.entity.task.CjTaskDO;
import com.atom.process.cnmuseum.cj.render.CJRender;
import com.atom.process.cnmuseum.cj.service.CaijiService;
import com.atom.process.cnmuseum.cj.service.CangPinService;
import com.atom.process.cnmuseum.cj.service.LuruService;
import com.atom.process.cnmuseum.cj.service.NeiRongShenheService;
import com.atom.process.cnmuseum.cj.service.ServiceInterface;
import com.atom.process.cnmuseum.cj.service.TaskListService;
import com.atom.process.cnmuseum.cj.service.ZiYuanShenheService;
import com.atom.process.cnmuseum.cj.tool.PageUtils;
import com.atom.process.cnmuseum.cj.tool.ProcessDefinitions;
import com.atom.process.cnmuseum.cj.tool.TaskDefinitions;
import com.atom.process.cnmuseum.cj.vo.QueryVO;
import com.atom.process.cnmuseum.cj.vo.request.DbrwRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.GcxxRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.MultimediaRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.RequestVO;
import com.atom.process.cnmuseum.cj.vo.request.TrackmessageRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.WhrlxxxRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.WhsxRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.XzxxRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.XzyxRequestVO;
import com.atom.process.cnmuseum.cj.vo.request.YxxxRequestVO;
import com.atom.process.cnmuseum.cj.vo.response.ResponseVO;
import com.sinosoft.cnmuseum.dao.MbMusicGcxxDao;
import com.sinosoft.cnmuseum.utils.LogUtils;
import com.sinosoft.cnmuseum.utils.Status;
import com.sinosoft.cnmuseum.utils.StringUtils;
import com.sinosoft.commontools.record.Record;

@Controller
@RequestMapping("cj")
public class MainController extends AbstractMainController {

    private static Logger logger = Logger.getLogger(MainController.class);

    private static final String VIEW_PREFIX = "cj/";
    private static final String DIAGRAM_VIEW = "contractFlowChart";
    private static final String LOG_VIEW = "log";

    /**
     * Description: 暂存
     *
     * @param processDefinitionId
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String save(@ModelAttribute RequestVO vo,
                       @ModelAttribute GcxxRequestVO gcxxvo,
                       @ModelAttribute XzxxRequestVO xzxxvo,
                       @ModelAttribute YxxxRequestVO yxxxvo,
                       @ModelAttribute WhrlxxxRequestVO whrlxxxvo,
                       HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        try {
            UserUtil user = new UserUtil(request);
            String taskid = vo.getTaskId();
            String taskDefKey = "";
            // 获取流程
            if (StringUtils.isEmpty(taskid)) {// 未创建流程，县创建流程，在保存
                // 创建流程
                String taskId = caijiService.create(user, gcxxvo.getCollection_code());
                // 获取流程参数
                ResponseVO newvo = render.getDetail(taskId, user);
                // 设置流程参数
                vo.setTaskId(newvo.getVo().getTaskId());
                vo.setProcessId(newvo.getVo().getProcessId());
                // 设置流程步骤
                taskDefKey = TaskDefinitions.采集.getKey();
            } else {// 已创建流程，直接保存
                List<RunningTaskDO> lists = taskListService.getRunningTaskListByTaskId(taskid);
                taskDefKey = lists.get(0).getTaskDefinitionKey();
            }
            // 保存
            ServiceInterface service = getService(taskDefKey);
            service.save(vo, gcxxvo, xzxxvo, yxxxvo, whrlxxxvo,user);
            Record record = new Record();
            record.add(Status.SATUS, Status.OK);
            return record.toJsonStr();
        } catch (Exception e) {
            logger.error("error message = {}" + e.getMessage(), e);
            Record record = new Record();
            record.add(Status.SATUS, Status.FAILED);
            record.add(Status.DATA, e.getMessage());
            return record.toJsonStr();
        }
    }
    
    
	@RequestMapping(value = "/uniqueCode", method = RequestMethod.POST)
    @ResponseBody
    public String uniqueCode(HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        Record record = new Record();
        try {
        	String Collection_code = request.getParameter("collection_code");
        	// 先判断藏品编号是否重复
            List<Record> lists_rs = new MbMusicGcxxDao().getIsNewDatas(Collection_code);
        	if(lists_rs!=null&&lists_rs.size()>0){
        		// 已经存在此编号
        		throw new Exception("藏品编号："+Collection_code+"已经存在，请重新输入！");
        	}
        	List<CjGcxxTaskDO> lists_atom = cjGcxxTaskDao.findByProperty("collection_code", Collection_code);
//        	String query ="select * from atm_cj_gcxx_task where collection_code='"+Collection_code+"'";
//        	List<CjGcxxTaskDO> lists_atom = cjGcxxTaskDao.executeSql(query, CjGcxxTaskDO.class);
        	if(lists_atom!=null&&lists_atom.size()>0){
        		// 已经存在此编号
        		throw new Exception("藏品编号："+Collection_code+"正在录入，请重新输入！");
        	}
            record.add(Status.SATUS, Status.OK);
            return record.toJsonStr();
        } catch (Exception e) {
            logger.error("error message = {}" + e.getMessage(), e);
            record.add(Status.SATUS, Status.FAILED);
            record.add(Status.MSG, e.getMessage());
            return record.toJsonStr();
        }
    }


    /**
     * Description: 获取详细信息
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/commentlist", method = RequestMethod.GET)
    @ResponseBody
    public String getCommentList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        String taskId = params.getTask_id();
        CjTaskDO cj = cjTaskDao.findByTaskId(taskId);
        return super.getCommentByTaskId(cj.getProcessId());
    }

    /**
     * Description: 提交
     *
     * @param processDefinitionId
     * @return
     */
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    @ResponseBody
    public String submit(@ModelAttribute RequestVO vo,
                         @ModelAttribute GcxxRequestVO gcxxvo,
                         @ModelAttribute XzxxRequestVO xzxxvo,
                         @ModelAttribute YxxxRequestVO yxxxvo,
                         @ModelAttribute WhrlxxxRequestVO whrlxxxvo,
                         HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        try {
            UserUtil user = new UserUtil(request);
            String taskid = vo.getTaskId();
            String taskDefKey = "";
            // 获取流程
            if (StringUtils.isEmpty(taskid)) {// 未创建流程，先创建流程，再提交
                // 创建流程
                String taskId = caijiService.create(user, gcxxvo.getCollection_code());
                // 获取流程参数
                ResponseVO newvo = render.getDetail(taskId, user);
                // 设置流程参数
                vo.setTaskId(newvo.getVo().getTaskId());
                vo.setProcessId(newvo.getVo().getProcessId());
                // 设置流程步骤
                taskDefKey = TaskDefinitions.采集.getKey();
            } else {// 已创建流程，直接提交
                List<RunningTaskDO> lists = taskListService.getRunningTaskListByTaskId(taskid);
                taskDefKey = lists.get(0).getTaskDefinitionKey();
            }
            // 提交
            ServiceInterface service = getService(taskDefKey);
            service.save(vo, gcxxvo, xzxxvo, yxxxvo, whrlxxxvo,user);
            vo.setBiaoti("采集_"+gcxxvo.getCollection_code());
            service.submit(vo, user);
            Record result = new Record();
            result.add(Status.SATUS, Status.OK);
            return result.toJsonStr();
        } catch (Exception e) {
            logger.error("error message = {}" + e.getMessage(), e);
            Record result = new Record();
            result.add(Status.SATUS, Status.FAILED);
            return result.toJsonStr();
        }
    }

    /**
     * Description: 新建
     *
     * @return

     @RequestMapping(value = "create", method = RequestMethod.GET)
     public String create(HttpServletRequest request,
     @RequestParam(value = "biaoti", required = true) String biaoti) {
     logger.info("REQUEST: " + request.getRequestURL().toString());
     UserUtil user = new UserUtil(request);
     ResponseVO vo = new ResponseVO();
     try {
     String taskId = caijiService.create(user, biaoti);
     vo = render.getDetail(taskId, user);
     vo.setTaskDefKey(TaskDefinitions.采集.getKey());
     vo.setStatus(1);
     } catch (Exception e) {
     logger.error("error message = {}" + e.getMessage(), e);
     vo.setStatus(0);
     vo.setErrorInfo("创建失败");
     }
     return vo.toString();
     }
     */
    /**
     * Description: 删除
     *
     * @param processDefinitionId
     * @return
     */
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    @ResponseBody
    public String delete(@ModelAttribute RequestVO vo,
                         HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        try {
            UserUtil user = new UserUtil(request);
            caijiService.delete(vo, user);
            Record result = new Record();
            result.add(Status.SATUS, Status.OK);
            return result.toJsonStr();
        } catch (Exception e) {
            logger.error("error message = {}" + e.getMessage(), e);
            Record result = new Record();
            result.add(Status.SATUS, Status.FAILED);
            return result.toJsonStr();
        }
    }

    /**
     * Description: 获取列表
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/cjlist", method = RequestMethod.GET)
    @ResponseBody
    public String getList(@ModelAttribute QueryVO params,
                          HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getList(params, request).toJsonStr();
    }

    /**
     * Description: 获取详细信息
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/getdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getDetail(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getDetail(params.getTask_id()).toJsonStr();
    }


    /**
     * Description: 代表人物
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/dbrwlist", method = RequestMethod.GET)
    @ResponseBody
    public String getDbrwList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getDbrwList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/dbrwdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getDbrwDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getDbrwDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savedbrw", method = RequestMethod.POST)
    @ResponseBody
    public String saveDbrw(@ModelAttribute DbrwRequestVO dbrwvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveDbrw(dbrwvo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletedbrw", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteDbrw(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteDbrw(id,user).toJsonStr();
    }
    
    /**
     * 多媒体信息
     */
    @RequestMapping(value = "/multimedialist", method = RequestMethod.GET)
    @ResponseBody
    public String getMultimediaList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getMultimediaList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/multimediadetail", method = RequestMethod.GET)
    @ResponseBody
    public String getMultimediaDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getMultimediaDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savemultimedia", method = RequestMethod.POST)
    @ResponseBody
    public String saveMultimedia(@ModelAttribute MultimediaRequestVO multimediavo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveMultimedia(multimediavo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletemultimedia", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteMultimedia(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteMultimedia(id,user).toJsonStr();
    }
    
    /**
     * 曲目信息
     */
    @RequestMapping(value = "/trackmessagelist", method = RequestMethod.GET)
    @ResponseBody
    public String getTrackmessageList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getTrackmessageList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/trackmessagedetail", method = RequestMethod.GET)
    @ResponseBody
    public String getTrackmessageDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getTrackmessageDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savetrackmessage", method = RequestMethod.POST)
    @ResponseBody
    public String saveTrackmessage(@ModelAttribute TrackmessageRequestVO trackmessagevo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveTrackmessage(trackmessagevo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletetrackmessage", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteTrackmessage(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteTrackmessage(id,user).toJsonStr();
    }
    /**
     * 形制文件信息
     */
    
    @RequestMapping(value = "/xzwjxxlist", method = RequestMethod.GET)
    @ResponseBody
    public String getXzwjxxList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxList(params.getTask_id(),"xz").toJsonStr();
    }

    @RequestMapping(value = "/xzwjxxdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getXzwjxxDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savexzwjxx", method = RequestMethod.POST)
    @ResponseBody
    public String saveXzwjxx(@ModelAttribute XzyxRequestVO xzyxvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveXzyx(xzyxvo,user,"xz").toJsonStr();
    }
    @RequestMapping(value = "/deletexzwjxx", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteXzwjxx(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteXzyx(id,user,"xz").toJsonStr();
    }
    
    
    /**
     * 音响文件信息
     */
    
    @RequestMapping(value = "/yxwjxxlist", method = RequestMethod.GET)
    @ResponseBody
    public String getYxwjxxList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxList(params.getTask_id(),"xz").toJsonStr();
    }

    @RequestMapping(value = "/yxwjxxdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getYxwjxxDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getXzyxDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/saveyxwjxx", method = RequestMethod.POST)
    @ResponseBody
    public String saveYxwjxx(@ModelAttribute XzyxRequestVO xzyxvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveXzyx(xzyxvo,user,"yx").toJsonStr();
    }
    @RequestMapping(value = "/deleteyxwjxx", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String deleteYxwjxx(@RequestParam("zdbh") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteXzyx(id,user,"yx").toJsonStr();
    }
    
        
    
    /**
     * Description: 文化事项
     *
     * @param taskId
     * @param request
     * @return
     */
    @RequestMapping(value = "/whsxlist", method = RequestMethod.GET)
    @ResponseBody
    public String getWhsxList(@ModelAttribute QueryVO params,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getWhsxList(params.getTask_id()).toJsonStr();
    }

    @RequestMapping(value = "/whsxdetail", method = RequestMethod.GET)
    @ResponseBody
    public String getWhsxDetail(@RequestParam(value = "id", required = true) String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return service.getWhsxDetail(id).toJsonStr();
    }
    @RequestMapping(value = "/savewhsx", method = RequestMethod.POST)
    @ResponseBody
    public String saveWhsx(@ModelAttribute WhsxRequestVO whsxvo,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.saveWhsx(whsxvo,user).toJsonStr();
    }
    @RequestMapping(value = "/deletewhsx", method = RequestMethod.GET)
    @ResponseBody
    public String deleteWhsx(@RequestParam("id") String id,
                            HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        return service.deleteWhsx(id,user).toJsonStr();
    }
    
    /**
     * Description: 查看待办详细
     *
     * @param taskDefKey
     * @param taskId
     * @return
     */
    @RequestMapping(value = "/detail/{taskDefKey}/{taskId}", method = RequestMethod.GET)
    public String getDetail(@PathVariable("taskDefKey") String taskDefKey,
                            @PathVariable("taskId") String taskId, HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);

        String view = VIEW_PREFIX;
        // if (TaskDefinitions.编目申请.equal(taskDefKey) ||
        // TaskDefinitions.部门主任审核.equal(taskDefKey)) {
        // view = view + "xiuGaiBianMuShenQing";
        // } else {
        // view = view + "xiuGaiBianMuShenHe";
        // }
        if (TaskDefinitions.采集.equal(taskDefKey)) {
            view = view + "caiji";
        } else if (TaskDefinitions.录入.equal(taskDefKey)) {
            view = view + "luru";
        } else if (TaskDefinitions.内容审核.equal(taskDefKey)) {
            view = view + "neirongshenhe";
        } else if (TaskDefinitions.资源审核.equal(taskDefKey)) {
            view = view + "ziyuanshenhe";
        }

        ResponseVO vo = new ResponseVO();
        try {
            vo = render.getDetail(taskId, user);
            vo.setTaskDefKey(taskDefKey);
            vo.setStatus(1);
        } catch (Exception e) {
            vo.setStatus(0);
        }
        return vo.toString();
        // return new ModelAndView(view, "data",
        // JsonUtil.ObjectToJsonQuietly(vo));
    }

    /**
     * Description: 查看流程图
     *
     * @param mainProcessInstanceId
     * @return
     */
    @RequestMapping(value = "/diagram/{mainProcessInstanceId}", method = RequestMethod.GET)
    public ModelAndView getDiagram(
            @PathVariable("mainProcessInstanceId") String mainProcessInstanceId,
            HttpServletResponse response, HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return super.getDiagram(mainProcessInstanceId,
                ProcessDefinitions.PROCESS_DEF_KEY, VIEW_PREFIX + DIAGRAM_VIEW,
                response);
    }

    /**
     * Description: 查看已办详细
     *
     * @param taskId
     * @return
     */
    @RequestMapping(value = "/history/{taskId}", method = RequestMethod.GET)
    public void getHistory(@PathVariable("taskId") String taskId,
                           HttpServletResponse response, HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        try {
            super.getHistory(taskId, response);
        } catch (Exception e) {
            logger.error("error message = {}" + e.getMessage(), e);
        }
    }

    /**
     * Description: 查看操作日志
     *
     * @param mainProcessInstanceId
     * @return
     */
    @RequestMapping(value = "/log/{mainProcessInstanceId}", method = RequestMethod.GET)
    public ModelAndView getLog(
            @PathVariable("mainProcessInstanceId") String mainProcessInstanceId,
            HttpServletResponse response, HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        return super.getLog(mainProcessInstanceId, LOG_VIEW, response);
    }


    @RequestMapping(value = "getRunningTaskListJson", method = RequestMethod.GET)
    @ResponseBody
    public String getRunningTaskListJson(HttpServletRequest request) {
        logger.info("REQUEST: " + request.getRequestURL().toString());
        UserUtil user = new UserUtil(request);
        int pagenumber = 1;
        int pagesize = 10;
        String taskDefinitionKey = request.getParameter("taskdefkey");
        String titlename = request.getParameter("titlename");
        try {
            String pagenumberstr = request.getParameter("pagenumber");
            pagenumber = Integer.parseInt(pagenumberstr);
        } catch (Exception e) {
        }
        try {
            String pagesizestr = request.getParameter("pagesize");
            pagesize = Integer.parseInt(pagesizestr);
        } catch (Exception e) {
        }
        List<Object> rlist = new ArrayList<Object>();
        Map<String, Object> result = new HashMap<String, Object>();
        List<RunningTaskDO> list = null;
        try {
            int total = taskListService.getRunningTaskCount(user, titlename, taskDefinitionKey);
            PageUtils pageutil = new PageUtils(pagenumber, pagesize, total);
            list = taskListService.getRunningTaskList(user, titlename, taskDefinitionKey, pageutil.getStart(), pageutil.getPagesize());

            result.put(Status.ROWS, list);
            result.put(Status.TOTAL, total);
            result.put(Status.CODE, Status.CODE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            result.put(Status.CODE, Status.CODE_ERROR);
        }
        rlist.add(result);
        JSONArray array = new JSONArray(rlist);
        String ss = array.toString();
        //String ss = JsonUtil.ObjectToJsonQuietly(result);
        return ss.substring(1, ss.length() - 1);
    }

	/*-------------------------------------------------------------------------------------------------------------
     *
	 * 
	 * 
	 */

    private ServiceInterface getService(String taskDefKey) {
        if (TaskDefinitions.采集.equal(taskDefKey)) {
            return caijiService;
        }
        if (TaskDefinitions.录入.equal(taskDefKey)) {
            return luruService;
        }
        if (TaskDefinitions.内容审核.equal(taskDefKey)) {
            return nrshService;
        }

        if (TaskDefinitions.资源审核.equal(taskDefKey)) {
            return zyshService;
        }

        return null;
    }

    @Resource
    CaijiService caijiService;
    @Resource
    LuruService luruService;
    @Resource
    NeiRongShenheService nrshService;
    @Resource
    ZiYuanShenheService zyshService;

    @Resource
    CJRender render;
    @Resource
    CangPinService service;

    @Resource
    CjTaskDao cjTaskDao;
    @Resource
    TaskListService taskListService;
    @Resource
    CjGcxxTaskDao cjGcxxTaskDao;

}
